// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   LoginPanel.java

package com.boci.clientapp.authentication;

import com.boci.clientapp.authentication.action.LoginAction;
import com.boci.clientapp.main.ApplicationService;
import com.boci.clientapp.main.ClientAppLoader;
import com.boci.common.ui.control.*;
import com.boci.common.util.MessagesConfigurator;
import com.boci.common.util.PerformanceLogger;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;

public class LoginPanel extends JScrollPane
    implements ActionListener
{

    public void initConfig()
    {
        intPanelWidth = 730;
        intPanelHeight = 250;
    }

    public void setText(Locale pLocale)
    {
        setFont(pLocale);
        disclaimerPanel.setText(pLocale);
        langBtnsPanel.setText(pLocale);
        MessagesConfigurator msgConfigurator = ClientAppLoader.getMessagesConfigurator();
        lblApplicationName.setText(msgConfigurator.getUIMessages("LOGIN.COMPANY_NAME", pLocale));
        lblLogin.setText(msgConfigurator.getUIMessages("LOGIN.LOGIN", pLocale));
        lblGreeting.setText(msgConfigurator.getUIMessages("LOGIN.LOGIN_HEAD", pLocale));
        lblUserID.setText(msgConfigurator.getUIMessages("LOGIN.LOGIN_ID", pLocale));
        lblPassword.setText(msgConfigurator.getUIMessages("LOGIN.PASSWORD", pLocale));
        btnLogin.setText(msgConfigurator.getUIMessages("LOGIN.SUBMIT", pLocale));
        btnClear.setText(msgConfigurator.getUIMessages("LOGIN.RESET", pLocale));
        btnContactUs.setText(msgConfigurator.getUIMessages("COMMON.CONTACT_US", pLocale));
        if(ClientAppLoader.isStandalone())
            btnProxySetting.setText(msgConfigurator.getUIMessages("LOGIN.PROXY_SETTING", pLocale));
    }

    private void setFont(Locale pLocale)
    {
        lblApplicationName.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblLogin.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblGreeting.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblUserID.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblPassword.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        btnLogin.setFont(ClientAppLoader.getBoldButtonFont(pLocale));
        btnClear.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        btnContactUs.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        if(ClientAppLoader.isStandalone())
            btnProxySetting.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
    }

    public void initGUI(Locale pLocale)
    {
        contentPanel = new JPanel();
        contentPanel.setLayout(null);
        contentPanel.setPreferredSize(new Dimension(intPanelWidth, intPanelHeight));
        contentPanel.setBackground(Color.white);
        lblLogo = new JLabel();
        lblLogo.setBounds(0, 1, 120, 43);
        lblLogo.setIcon(ClientAppLoader.getLogo());
        contentPanel.add(lblLogo);
        lblApplicationName = new JLabel();
        lblApplicationName.setBounds(140, 5, 260, 42);
        contentPanel.add(lblApplicationName);
        lblLogin = new JLabel();
        lblLogin.setBorder(new EmptyBorder(0, 5, 0, 0));
        lblLogin.setOpaque(true);
        lblLogin.setForeground(Color.WHITE);
        lblLogin.setBackground(new Color(140, 143, 145));
        lblLogin.setBounds(131, 52, 488, 25);
        contentPanel.add(lblLogin);
        centerPanel = new JPanel();
        centerPanel.setLayout(null);
        centerPanel.setBackground(Color.WHITE);
        centerPanel.setBounds(131, 77, 488, 166);
        centerPanel.setBorder(BorderFactory.createTitledBorder(""));
        contentPanel.add(centerPanel);
        if(ClientAppLoader.isStandalone())
        {
            btnProxySetting = new JButton();
            btnProxySetting.setBounds(650, 1, 88, 19);
            btnProxySetting.setMargin(new Insets(0, 0, 0, 0));
            btnProxySetting.setActionCommand("PROXY_ACTION");
            btnProxySetting.addActionListener(this);
            contentPanel.add(btnProxySetting);
        }
        lblUserID = new JLabel();
        lblUserID.setHorizontalAlignment(4);
        lblUserID.setBounds(53, 60, 106, 20);
        centerPanel.add(lblUserID);
        lblPassword = new JLabel();
        lblPassword.setHorizontalAlignment(4);
        lblPassword.setBounds(47, 90, 112, 20);
        centerPanel.add(lblPassword);
        txtUserID = new JTextField();
        txtUserID.setBounds(197, 60, 153, 20);
        centerPanel.add(txtUserID);
        pwdPassword = new JPasswordField();
        pwdPassword.setBounds(197, 90, 153, 20);
        centerPanel.add(pwdPassword);
        btnLogin = new JButton();
        btnLogin.setBounds(109, 130, 120, 25);
        btnLogin.setActionCommand("LOGIN_ACTION");
        btnLogin.addActionListener(this);
        centerPanel.add(btnLogin);
        btnClear = new JButton();
        btnClear.setBounds(259, 130, 120, 25);
        btnClear.setActionCommand("CLEAR_ACTION");
        btnClear.addActionListener(this);
        centerPanel.add(btnClear);
        lblGreeting = new JLabel();
        lblGreeting.setBounds(9, 9, 468, 30);
        centerPanel.add(lblGreeting);
        btnContactUs = new CMURLButton();
        btnContactUs.setBounds(530, 1, 80, 20);
        btnContactUs.setActionCommand("CONTACTUS_ACTION");
        btnContactUs.addActionListener(this);
        contentPanel.add(btnContactUs);
        langBtnsPanel = new LangBtnsPanel(pLocale);
        langBtnsPanel.setBounds(610, 0, 40, 20);
        contentPanel.add(langBtnsPanel);
        disclaimerPanel = new DisclaimerPanel(pLocale);
        rootPanel = new JPanel();
        rootPanel.setLayout(new BorderLayout());
        rootPanel.add(contentPanel, "Center");
        rootPanel.add(disclaimerPanel, "South");
        rootPanel.setBackground(Color.white);
        setViewportView(rootPanel);
    }

    public LoginPanel(Locale pLocale)
    {
        initConfig();
        initGUI(pLocale);
        setText(pLocale);
    }

    public void actionPerformed(ActionEvent e)
    {
        if(validate(e.getActionCommand()))
        {
            PerformanceLogger.startAppTimer();
            String strActionType = e.getActionCommand();
            LoginAction action = new LoginAction();
            action.doProcess(getInputValue(strActionType), strActionType);
            PerformanceLogger.stopAppTimer();
            PerformanceLogger.doLog((new StringBuilder()).append("LOGIN_SCREEN.").append(strActionType).toString());
        }
    }

    private HashMap getInputValue(String ActionType)
    {
        HashMap returnMap = new HashMap();
        String strUserID = txtUserID.getText();
        String strPasswd = String.copyValueOf(pwdPassword.getPassword());
        returnMap.put("login", strUserID);
        returnMap.put("password", strPasswd);
        return returnMap;
    }

    private boolean validate(String ActionType)
    {
        if(ActionType.equals("LOGIN_ACTION"))
        {
            ArrayList msgKeyList = new ArrayList();
            boolean validFlag = true;
            String strPass = String.copyValueOf(pwdPassword.getPassword());
            String strID = txtUserID.getText();
            if(strID == null || strID.equals(""))
            {
                msgKeyList.add("LOGIN.MISSING_ID");
                validFlag = false;
            }
            if(strPass == null || strPass.equals(""))
            {
                msgKeyList.add("LOGIN.MISSING_PASSWD");
                validFlag = false;
            }
            if(!validFlag)
            {
                ApplicationService.getInstance().showWarningDialog(null, msgKeyList);
                return false;
            }
        }
        return true;
    }

    public void refresh()
    {
        txtUserID.setText("");
        pwdPassword.setText("");
        setDefFocus();
    }

    public void setDefFocus()
    {
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                txtUserID.requestFocus();
            }
        }
);
    }

    private JLabel lblGreeting;
    private JButton btnClear;
    private JButton btnLogin;
    private JPasswordField pwdPassword;
    private JTextField txtUserID;
    private JLabel lblPassword;
    private JLabel lblUserID;
    private JPanel centerPanel;
    private JLabel lblLogin;
    private JLabel lblApplicationName;
    private JLabel lblLogo;
    private JPanel contentPanel;
    private JPanel rootPanel;
    private CMURLButton btnContactUs;
    private LangBtnsPanel langBtnsPanel;
    private DisclaimerPanel disclaimerPanel;
    private JButton btnProxySetting;
    private int intPanelHeight;
    private int intPanelWidth;

}
